package com.xiaoyu.lanling.feature.chat.model.message

import `in`.srain.cube.request.JsonData
import android.graphics.Color
import com.xiaoyu.base.app.AppContext
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.media.image.ImageLoadParam

class RewardInfo(jsonData: JsonData) {

    val desc = jsonData.optString("desc")
    val icon = jsonData.optString("icon")
    val textColor = parseLastContentTextColor(jsonData.optString("textColor"))
    val iconloadParam = ImageLoadParam.newBuilder().setUrl(icon).setSizeInDP(16).build()

    private fun parseLastContentTextColor(colorString: String): Int {
        return if (colorString.isEmpty()) {
            AppContext.getColor(R.color.colorWhite)
        } else try {
            Color.parseColor(colorString)
        } catch (e: Throwable) {
            AppContext.getColor(R.color.colorWhite)
        }
    }
}